package com.commons.utils;

import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;

/**
 * @author mis_wu
 * @date 2022/3/26 20:33
 */
@Slf4j
public class AutoGenerateIds {

    /**
     * workerId 0~31(Long)
     * datacenterId  0~31(Long)
     */
    private static final Long workerId = 0L;
    private static final Long datacenterId = 0L;

    /**
     * 生成0~31的随机数
     * @return
     */
    private static Long getRandom(){
        //0~31
        return (Long) (long) (int) (Math.random()*32);
    }

    /**
     * 生成随机id的数量
     * @param count
     * @return
     */
    public static List<Long> getGenerateId(int count){
        //当机器码不够用可以通过随机数给workerId，datacenterId赋值
        //workerId = getRandom();
        List ids = new ArrayList();
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(workerId, datacenterId);
        for (int i=0;i<count;i++){
            ids.add(idWorker.nextId());
        }
        return ids;
    }

}
